﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class SolicitudesPractica_FormGestionarSolicitudes : System.Web.UI.Page
{
    static DataTable solicitudes;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CargarEmpresas();
            if (Session["nomUsr"] != null)
                if(Request.QueryString["nit"] != null)
                    DropDownListEmpresa.SelectedValue = Request.QueryString["nit"].ToString();
            ButtonBuscar_Click(null, null);
        }

        if (Session["nit"] != null)
        {
            DropDownListEmpresa.SelectedValue = Session["nit"].ToString();
            DropDownListEmpresa.Enabled = false;
            ButtonBuscar_Click(null, null);
        }
    }

    protected void CargarEmpresas()
    {
        Empresa tmp = new Empresa();
        List<Empresa> empresas = tmp.consultarEmpresa();
        foreach (Empresa emp in empresas)
            DropDownListEmpresa.Items.Add(new ListItem(emp.ObtNombre(), emp.ObtNit()));
    }

    protected void ButtonBuscar_Click(object sender, EventArgs e)
    {
        string estado = DropDownListEstado.SelectedValue.ToString();
        string nombreEmp = TextBoxNomEmpresa.Text;
        string nitEmpresa = DropDownListEmpresa.SelectedValue;
        string fechaCreacion = TextBoxFecha.Text;
        SolicitudPractica sp = new SolicitudPractica();
        solicitudes = sp.BusquedaAvanzada(nombreEmp, nitEmpresa, fechaCreacion, estado);
        GVSolicitudes.DataSource = solicitudes;
        GVSolicitudes.DataBind();
        //cargarTablaDeSolicitudes(Filtrar(TextBoxNomEmpresa.Text, TextBoxFecha.Text, estado));
    }
    protected void DropDownListEstado_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GVSolicitudes_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GVSolicitudes.DataSource = solicitudes;
        GVSolicitudes.PageIndex = e.NewPageIndex;
        GVSolicitudes.DataBind();
    }
}
